package com.qf.wangqing.sportsnews.fragment.sliding;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.qf.wangqing.sportsnews.MyApplication;
import com.qf.wangqing.sportsnews.R;
import com.qf.wangqing.sportsnews.adapter.SlidingRecyclerAdapter;
import com.qf.wangqing.sportsnews.bean.slidingbean.HotRootEntity;
import com.qf.wangqing.sportsnews.databinding.FragmentHotBinding;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class HotFragment extends Fragment implements Callback<HotRootEntity> {
    private FragmentHotBinding binding;
    private Map<Class<?>,Pair<Integer,Integer>> map;
    private SlidingRecyclerAdapter adapter;

    public HotFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()),R.layout.fragment_hot,container,false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        map = new HashMap<>();

        MyApplication application = (MyApplication) getActivity().getApplication();
        application.getSlidingService().getHotList().enqueue(this);

//        map.put(HotDataEntity.class,Pair.create(R.layout.item_hot_sliding, BR.slidingdata));
//        map.put(HotDataEntity.class,Pair.create(R.layout.img2_item_hot,BR.slidingdata));
//        map.put(HotDataEntity.class,Pair.create(R.layout.img_item_hot,BR.slidingdata));
//        adapter = new SlidingRecyclerAdapter(getContext(),new ArrayList(),map);


    }

    @Override
    public void onResponse(Call<HotRootEntity> call, Response<HotRootEntity> response) {
        HotRootEntity body = response.body();
        //一张图片的
//        if (body.getData().size()!=0) {
//            adapter.addAll(0,body.getData());
//        }
//        if (body.getData().size()<4){//两张三张图片的
//
//            adapter.addAll(1,body.getData());
//
//        }
//        if (body.getData().size()>3){//4 5 6张图片的
//            adapter.add(2,body.getData());
//        }

//        binding.recyclerviewHotfragment.setAdapter(adapter);
    }

    @Override
    public void onFailure(Call<HotRootEntity> call, Throwable t) {
        t.printStackTrace();
        Toast.makeText(getContext(),t.getMessage(),Toast.LENGTH_SHORT).show();
    }
}
